<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>评价</title>  
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Wx/css/base.css" />
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Wx/css/detail.css" />
</head>
<body> 
<div class="detail">

	<form method="post" action="<?=U('WholesaleOrder/addEva')?>" class="js_form" enctype="multipart/form-data">
		<div class="evaluate">
			<div class="writ"><textarea name="content" style="resize:none;" placeholder="说说你对产品的评价吧！" required></textarea></div>
			<input type="hidden" value="<?=$w_id?>" name="w_id">
			<input type="hidden" value="<?=$g_id?>" name="g_id">
			<div class="pic">
				<ul>
					<li>
						<div class="up" onClick="upimg('1')"><img src="__PUBLIC__/Wx/img/camera.png" id="img1"/><em>图片1</em></div>
						<input id="img_1" name="img_1" type="file" style="display:none;" type="text" value="">
					</li>
					<li>
						<div class="up" onClick="upimg('2')"><img src="__PUBLIC__/Wx/img/camera.png" id="img2"/><em>图片2</em></div>
						<input id="img_2" name="img_2"  type="file" style="display:none;" type="text" value="">
					</li>
					<li>
						<div class="up" onClick="upimg('3')"><img src="__PUBLIC__/Wx/img/camera.png" id="img3"/><em>图片3</em></div>
						<input id="img_3" name="img_3"  type="file" style="display:none;" type="text" value="">
					</li>

				</ul>
			</div>
			<div class="anonymity"><span><input type="radio" name="is_inco" value="1"/>匿名点评</span></div>
		</div>
		<div class="button"><input type="submit" value="发布评价"/></div>
	</form>

	<!--引用悬浮公共导航文件-->
	<include file="Public:nav" />


</div>
<script type="text/javascript" src="__PUBLIC__/js/jquery.min.js?v=2.1.4"></script>
<script src="__PUBLIC__/js/jquery.form.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
	<script type="text/javascript">
		//表单提交
		$(".js_form").ajaxForm({
			//定义返回JSON数据，还包括xml和script格式
			dataType: 'json',
			success: function(data) {
			    console.log(data)
				//提交成功后调用
				if(data.state > 0) {
                    layer.msg(data.val, {icon:2,time:1000});
                }else{
                    layer.msg(data.val, {icon:1,time:1000},
                        function(){
                            window.location.href="__MODULE__/WholesaleOrder/detail/id/{$w_id}";
                        });
				}
			}
		});

        $(".click span").click(function(){
            if($(this).text() ==="导航"){
                $(this).text("收起");
                $('.link02').css('display','block')
            }else{
                $(this).text("导航");
                $('.link02').css('display','none')
            }
        });

        //模拟图片选择器
        function upimg(num) {
            //input file 模拟点击
            if($("#img_"+num).attr("type")!="file")$("#img_"+num).attr("type","file");
            $("#img_"+num).click();
        };//end fun

        var imgcss = {
            width:'84px',
			height:'84px',
			margin:0,
        };

        $("#img_1").change(function () {
            var formData = new FormData();
            var picinput = document.getElementById("img_1");
            var domain = 'http://www.xiangtws.com';
            var proportion = '1:1';  //图片比例
            var imgsrc = $("#img1");//img标签
			imgsrc.attr("src", '__PUBLIC__/Wx/img/loading.gif');//加载gif图片
            formData.append('pic', picinput.files[0]);       //将图片信息追加到formdata中
            formData.append('proportion', proportion);       //将图片比例追加到formdata中
            formData.append('domain', domain);       //将图片信息追加到formdata中
            $.ajax({
                url: 'http://imgs.xiangtws.com/Api/Index/addPic',
                type: 'POST',
                data: formData,                    // 上传formdata封装的数据
                dataType: 'JSON',
                cache: false,                      // 不缓存
                processData: false,                // jQuery不要去处理发送的数据
                contentType: false,                // jQuery不要去设置Content-Type请求头
                success: function (data) {           //成功回调
                    //回显                    
                    imgsrc.attr("src", data.url);
                    imgsrc.next().hide();
                    //input标签类型修改
                    $("#img_1").attr("type", "text");
                    $("#img_1").attr("value", data.url + ',');
                    imgsrc.css(imgcss);
                },
                error: function (data, XMLHttpRequest, textStatus, errorThrown) {
                    console.log('error');
                }
            });

        })//end fun

        $("#img_2").change(function () {
            var formData = new FormData();
            var picinput = document.getElementById("img_2");
            var domain = 'http://www.xiangtws.com';
            var proportion = '1:1';  //图片比例
            var imgsrc=$("#img2");//img标签
			imgsrc.attr("src", '__PUBLIC__/Wx/img/loading.gif');//加载gif图片
            formData.append('pic', picinput.files[0]);       //将图片信息追加到formdata中
            formData.append('proportion', proportion);       //将图片比例追加到formdata中
            formData.append('domain', domain);       //将图片信息追加到formdata中
            $.ajax({
                url:'http://imgs.xiangtws.com/Api/Index/addPic',
                type:'POST',
                data:formData,                    // 上传formdata封装的数据
                dataType:'JSON',
                cache:false,                      // 不缓存
                processData:false,                // jQuery不要去处理发送的数据
                contentType:false,                // jQuery不要去设置Content-Type请求头
                success:function (data) {           //成功回调
                    //回显
                    imgsrc.attr("src",data.url);
                    imgsrc.next().hide();
                    //input标签类型修改
                    $("#img_2").attr("type","text");
                    $("#img_2").attr("value",data.url+',');
                    imgsrc.css(imgcss);
                },
                error: function (data,XMLHttpRequest, textStatus, errorThrown) {
                    console.log('error');
                }
            });

        })//end fun

        $("#img_3").change(function () {
            var formData = new FormData();
            var picinput = document.getElementById("img_3");
            var domain = 'http://www.xiangtws.com';
            var proportion = '1:1';  //图片比例
            var imgsrc=$("#img3");//img标签
			imgsrc.attr("src", '__PUBLIC__/Wx/img/loading.gif');//加载gif图片
            formData.append('pic', picinput.files[0]);       //将图片信息追加到formdata中
            formData.append('proportion', proportion);       //将图片比例追加到formdata中
            formData.append('domain', domain);       //将图片信息追加到formdata中
            $.ajax({
                url:'http://imgs.xiangtws.com/Api/Index/addPic',
                type:'POST',
                data:formData,                    // 上传formdata封装的数据
                dataType:'JSON',
                cache:false,                      // 不缓存
                processData:false,                // jQuery不要去处理发送的数据
                contentType:false,                // jQuery不要去设置Content-Type请求头
                success:function (data) {           //成功回调
                    //回显
                    imgsrc.attr("src",data.url);
                    imgsrc.next().hide();
                    //input标签类型修改
                    $("#img_3").attr("type","text");
                    $("#img_3").attr("value",data.url+',');
                    imgsrc.css(imgcss);
                },
                error: function (data,XMLHttpRequest, textStatus, errorThrown) {
                    console.log('error');
                }
            });

        })//end fun


        // 是否匿名
		$(document).ready(function(e) {
    		$(".anonymity span").click(function(){
        		if($(this).hasClass("select")){
            		$(this).removeClass("select");
                    $("input[name='is_inco']").val(1)
                }else{
            		$(this).addClass("select");
                    $("input[name='is_inco']").val(0)
        		}
    		})
		});



	</script>
</body>
</html>